<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link type="text/css" rel="stylesheet" href="<%=basePath %>jquery-easyui-1.4.2/themes/default/easyui.css">
<link type="text/css" rel="stylesheet" href="<%=basePath %>jquery-easyui-1.4.2/themes/icon.css">
<script type="text/javascript" src="<%=basePath %>js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="<%=basePath %>jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=basePath %>jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
	.input{
		margin-top: 10px;
		width: 195px;
	} 
	.inputs{
		width: 50%;
		height: 20px;
		margin-top: 10px;
		margin-left: 20%;
	} 
	td{
	width: 200px;
	text-align: center;
	}
</style>
<script type="text/javascript">

$(function(){
	$('#win').window('close');  // close a window  
	$('#win2').window('close');  // close a window 
	$('#win3').window('close');  // close a window 
});

	//添加节点，打开窗口
	function addNode(){
		$('#win').window('open');  // close a window  
	}
	//添加根节点
	function addjs(){
		var selections = $("#dg").datagrid("getSelections");
		if(selections == ""){
			var menuid =  -1;
			var menuLevel =2;
			menuparentld = 8;
			var menuUrl = "";
		}else{
			var menuparentld = selections[0].menuid;
			var menuid =  1;
			var menuLevel =3;
			var menuUrl = "leibieguanli.jsp";
		}
		var menuname = $("#menuname").val();
		var menuisShow = $("#menuisShow").combobox("getValue");
		if(menuisShow == -1){
			$.messager.alert('提示','请选择使用状态','info',function(){
				$('#win').window('close');  // close a window  
				$("#dg").datagrid("reload");
				$('#win').window('open');  // open a window 
				return;
			});
		}else{
		$.post("<%=basePath%>user/addjs.do",{
			'menuid':menuid,
			'menuLevel':menuLevel,
			'menuUrl':menuUrl,
			'menuname':menuname,
			'menuisShow':menuisShow,
			'menuparentld':menuparentld
		},function(data){
			if(data.result=="OK"){
				msg="插入节点成功！";
			}
			$.messager.alert('提示信息',msg,'info',function(){
				$('#win').window('close');  // close a window  
				$("#dg").datagrid("reload");
			});
		},"json");
		}
	}
 	//打开窗口. 修改节点 id=dg
	function updateNode(){
		$('#win2').window('open');  // open a window 
		var selections = $("#dg").datagrid("getSelections");
		var menuid  = selections[0].menuid;
		var menuname  = selections[0].menuname;
		var menuisShow  = selections[0].menuisShow;
		$("#menuid1").val(menuid);
		$("#menuname1").val(menuname);
		$("#menuisShow1").combobox("setValue",menuisShow);
	}
 	//打开窗口. 修改子节点id=qk
	function updateNodeson(){
		$('#win2').window('open');  // open a window 
		var selections = $("#qk").datagrid("getSelections");
		var menuid  = selections[0].menuid;
		var menuname  = selections[0].menuname;
		var menuisShow  = selections[0].menuisShow;
		$("#menuid1").val(menuid);
		$("#menuname1").val(menuname);
		$("#menuisShow1").combobox("setValue",menuisShow);
	}
	//修改节点
	function updatenodejs(){
		var menuid = $("#menuid1").val();
		var menuname = $("#menuname1").val(); 
		var menuisShow = $("#menuisShow1").combobox("getValue");
		$.post("<%=basePath%>user/updatemenu.do",{
			"menuid":menuid,
			"menuname":menuname,
			"menuisShow":menuisShow,
		},function(data){
			$.messager.alert('提示信息','节点修改成功！','info',function(){
				$('#win2').window('close');  // close a window  
				$("#dg").datagrid("reload");
			});
		},"json");
	} 
	
	//打开窗口，删除节点
	function daleteNodedg(){
		$('#win3').window('open');  // open a window   
		var selections = $("#dg").datagrid("getSelections");
		var menuid  = selections[0].menuid;
		$("#menuid1").val(menuid);
	}
	//打开窗口，删除节点
	function daleteNodeqk(){
		$('#win3').window('open');  // open a window   
		var selections = $("#qk").datagrid("getSelections");
		var menuid  = selections[0].menuid;
		$("#menuid1").val(menuid);
	}
	//确定删除
	function confirmdelete(){
		var menuid = $("#menuid1").val();
		$.post("<%=basePath%>user/menudeletemenus.do",{
			"menuid":menuid
		},function(data){
			$.messager.alert('提示信息','节点删除成功！','info',function(){
				$('#win3').window('close');  // close a window  
				$("#dg").datagrid("reload");
			});
		},"json");
	}
	//关闭窗口
	function cancel(){
		$('#win').window('close');  // close a window  
	 	$('#win2').window('close');  // close a window  
	 	$('#win3').window('close');  // close a window  
	}
</script>
	</head>
		<body class="easyui-layout">
			<div data-options="region:'center',title:'类别查看'" >
			<a href="javascript:addNode();" class="easyui-linkbutton" data-options="iconCls:'icon-add2'">添加根节点</a>
			<hr style=" height:2px;border:none;border-top:2px solid #185598;" />
				<table class="easyui-datagrid" id="dg">   
				    <thead>   
				        <tr>   
				            <th  data-options="field:'menuid'">父节点序号</th>   
				            <th  data-options="field:'menuname'">名称</th>   
				            <th  data-options="field:'menuisShow'">状态</th>  
				            <th  data-options="field:'index'">操作</th>  
				        </tr>   
				    </thead>   
				    <tbody>   
				    <c:forEach items="${menus }" var="m2">
				    	<c:if test="${m2.menuLevel==2}">
					        <tr>   
					            <td>${m2.menuid}</td>
					            <td>${m2.menuname}</td>
					            <c:if test="${m2.menuisShow==1}">
						            <td>使用</td>   
					            </c:if>
					            <c:if test="${m2.menuisShow==0}">
						            <td>未使用</td>   
					            </c:if>  
					            <td>&nbsp&nbsp<a href='javascript:addNode();' style='color:blue'>添加子节点</a>&nbsp&nbsp<a href='javascript:updateNode()' style='color:blue'>修改</a>&nbsp&nbsp<a href='javascript:daleteNodedg();' style='color:blue'>删除</a>&nbsp&nbsp</td>   
					        </tr> 
				        </c:if>  
				    </c:forEach>
				    </tbody>   
				</table> 
			<hr style=" height:2px;border:none;border-top:2px solid #185598;" />
			<table class="easyui-datagrid" id="qk">   
				    <thead>   
				        <tr>   
				            <th  data-options="field:'menuid'">子节点序号</th>   
				            <th  data-options="field:'menuname'">子节点</th>   
				            <th  data-options="field:'menuisShow'">状态</th>  
				            <th  data-options="field:'index'">操作</th>  
				        </tr>   
				    </thead>   
				    <tbody>   
				    <c:forEach items="${menus }" var="m3">
				    	<c:if test="${m3.menuLevel==3}">
					        <tr>   
					            <td>${m3.menuid}</td>
					            <td>${m3.menuname}</td>
					            <c:if test="${m3.menuisShow==1}">
						            <td>使用</td>   
					            </c:if>
					            <c:if test="${m3.menuisShow==0}">
						            <td>未使用</td>   
					            </c:if>  
					            <td><a href='javascript:updateNodeson();' style='color:blue'>修改</a>&nbsp&nbsp<a href='javascript:daleteNodeqk();' style='color:blue'>删除</a>&nbsp&nbsp</td>   
					        </tr> 
				        </c:if>  
				    </c:forEach>
				    </tbody>   
				</table> 
	 		</div>
	 	<!-- 添加根节点的DIV -->
			<div id="win" class="easyui-window" title="添加节点" style="width:400px;height:170px"   
		        data-options="iconCls:'icon-save',modal:true,collapsible:true,minimizable:false,maximizable:false">   
		      <form action="" id="form2">
		      	<input type="hidden" id="menuparentld" name="menuparentld"/>
		        <div class="inputs"><input type="text" id="menuname"  class="input easyui-validatebox" name="menuname" placeholder="名称" /></div><br/>
		        <div class="inputs">
			        <select id="menuisShow" class="easyui-combobox" name="menuisShow" style="width:200px;">   
					    <option value = "-1">请选择状态</option>   
					    <option value = "1">使用</option>   
					    <option value = "0">未使用</option>   
					</select> 
				</div>
		        <div style="text-align: center; margin-top: 20px">
			        <a id="btn2" href="javascript:addjs();" class="easyui-linkbutton " data-options="iconCls:'icon-add2'">确认</a>  
			        <a id="btn3" href="javascript:cancel();" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">取消</a>
		        </div>  
		      </form>
			</div>
 	 	 <!-- 修改  -->
			<div id="win2" class="easyui-window" title="修改节点" style="width:400px;height:170px"   
		        data-options="iconCls:'icon-save',modal:true,collapsible:true,minimizable:false,maximizable:false">   
		      <form action="" id="form2">
		      	<input type="hidden" id="menuid1" name="menuid"/>
		        <div class="inputs"><input type="text" id="menuname1"  class="input easyui-validatebox" name="menuname" placeholder="名称" /></div><br/>
		        <div class="inputs">
			        <select id="menuisShow1" class="easyui-combobox" name="menuisShow" style="width:200px;">   
					    <option value = "-1">请选择状态</option>   
					    <option value = "1">使用</option>   
					    <option value = "0">未使用</option>   
					</select> 
				</div>
		        <div style="text-align: center; margin-top: 20px">
			        <a id="btn2" href="javascript:updatenodejs();" class="easyui-linkbutton " data-options="iconCls:'icon-add2'">确认</a>  
			        <a id="btn3" href="javascript:cancel();" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">取消</a>
		        </div>  
		      </form>
			</div>
			<!-- 删除的DIV -->
			<div id="win3" class="easyui-window" title="删除节点" style="width:350px;height:150px"   
		        data-options="iconCls:'icon-save',modal:true,collapsible:false,minimizable:false,maximizable:false">   
		        <div style="text-align: center; margin-top: 20px">
		        	<input type="hidden" id="menuid1" name="menuid"/>
		        	<span>您确认删除这条信息吗？</span><br/><br/><br/>
			        <a id="btn2" href="javascript:confirmdelete();" class="easyui-linkbutton " data-options="iconCls:'icon-add2'">确认</a>  
			        <a id="btn3" href="javascript:cancel();" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">取消</a>
	        	</div>  
			</div>
</body>
</html>
